const express = require('express')

const path = require('path')

const body = require('body-parser')

const cookie = require('cookie-parser')

const session =require('express-session')

const { port ,expires} = require('./config')

const router = require('./routers')

const {empty,error}=require('./middleware')

const {connect}= require('./db/index')

const app = express()

connect()

app.use('/static', express.static(path.resolve(__dirname, '../shop_client/')))
app.use('/public', express.static(path.resolve(__dirname,'./public')))

app.engine('html',require('express-art-template'))
app.set('views',path.resolve(__dirname,'../shop_client/pages/'))

app.use(cookie())

app.use(body({ extended: false }))
app.use(body.json())

app.use(session({
    secret:'zhoumingwei',
    resave:true,
    cookie:{maxAge:expires}
}))

app.use(router)

app.use(empty)
app.use(error)
app.listen(port, () => {
    console.log(
        `
        开启服务器成功
        目前正在监听${port}的端口
        `
    );
})